
window["Mz_Browser"]={};
(function()
		{
		if(Mz_Browser.platform) return;
		var ua = window.navigator.userAgent;
		Mz_Browser.platform = window.navigator.platform;

		Mz_Browser.firefox = ua.indexOf("Firefox")>0;
		Mz_Browser.opera = typeof(window.opera)=="object";
		Mz_Browser.ie = !Mz_Browser.opera && ua.indexOf("MSIE")>0;
		Mz_Browser.mozilla = window.navigator.product == "Gecko";
		Mz_Browser.netscape= window.navigator.vendor=="Netscape";
		Mz_Browser.safari= ua.indexOf("Safari")>-1;

		if(Mz_Browser.firefox) var re = /Firefox(\s|\/)(\d+(\.\d+)?)/;
		else if(Mz_Browser.ie) var re = /MSIE( )(\d+(\.\d+)?)/;
		else if(Mz_Browser.opera) var re = /Opera(\s|\/)(\d+(\.\d+)?)/;
		else if(Mz_Browser.netscape) var re = /Netscape(\s|\/)(\d+(\.\d+)?)/;
		else if(Mz_Browser.safari) var re = /Version(\/)(\d+(\.\d+)?)/;
		else if(Mz_Browser.mozilla) var re = /rv(\:)(\d+(\.\d+)?)/;

		if("undefined"!=typeof(re)&&re.test(ua))
		Mz_Browser.version = parseFloat(RegExp.$2);
})(); 
var	keyStr = "ABCDEFGHIJKLMNOP"    +     
         "QRSTUVWXYZabcdef"    +     
         "ghijklmnopqrstuv"    +     
         "wxyz0123456789+/"    +     
         "=";     

function    encode64(input)    {     
	input    =    escape(input);     
	var    output    =    "";     
	var    chr1,    chr2,    chr3    =    "";     
	var    enc1,    enc2,    enc3,    enc4    =    "";     
	var    i    =    0;    
	
	do {     
		chr1    =    input.charCodeAt(i++);     
		chr2    =    input.charCodeAt(i++);     
		chr3    =    input.charCodeAt(i++);     
		
		enc1    =    chr1    >>    2;     
		enc2    =    ((chr1    &    3)    <<    4)    |    (chr2    >>    4);     
		enc3    =    ((chr2    &    15)    <<    2)    |    (chr3    >>    6);     
		enc4    =    chr3    &    63;     
	
		if(isNaN(chr2))    {     
			enc3 = enc4 = 64;     
		}else if(isNaN(chr3)){     
			enc4 = 64;     
		}     
	
		output = output +     
		keyStr.charAt(enc1) +     
		keyStr.charAt(enc2) +     
		keyStr.charAt(enc3) +     
		keyStr.charAt(enc4);     
		chr1 = chr2 = chr3 = "";     
		enc1 = enc2 = enc3 = enc4 = "";     
	}while(i < input.length);    
	
	return output;     
}     

function decode64(input){     
	var output = "";     
	var chr1, chr2, chr3 = "";     
	var enc1, enc2, enc3, enc4 = "";     
	var i = 0;     
	
	//    remove    all    characters    that    are    not    A-Z,    a-z,    0-9,    +,    /,    or    =     
	var base64test = /[^A-Za-z0-9\+\/\=]/g;     
	if (base64test.exec(input)){     
		alert("There    were    invalid    base64    characters    in    the    input    text.\n"    +     
		"Valid    base64    characters    are    A-Z,    a-z,    0-9,    '+',    '/',    and    '='\n"    +     
		"Expect    errors    in    decoding.");     
		}     
	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");     
	
	do {     
		enc1 = keyStr.indexOf(input.charAt(i++));     
		enc2 = keyStr.indexOf(input.charAt(i++));     
		enc3 = keyStr.indexOf(input.charAt(i++));     
		enc4 = keyStr.indexOf(input.charAt(i++));     
		
		chr1 = (enc1 << 2) | (enc2 >> 4);     
		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);     
		chr3 = ((enc3 & 3) << 6) | enc4;     
		
		output = output + String.fromCharCode(chr1);     
		
		if (enc3 != 64){     
			output = output + String.fromCharCode(chr2);     
		}     
		if (enc4 != 64){     
			output = output + String.fromCharCode(chr3);     
		}     
		
		chr1 = chr2 = chr3 = "";     
		enc1 = enc2 = enc3 = enc4 = ""; 
	}while(i < input.length);
	
	return unescape(output);     
}       


/**
 * iframe 自动高度
 * 
 * @param obj
 * @return
 */
function SetCwinHeight(obj) {
	var iframeid = obj
	if (document.getElementById) {
		if (iframeid && !window.opera) {
			if (iframeid.contentDocument
					&& iframeid.contentDocument.body.offsetHeight) {
				iframeid.height = iframeid.contentDocument.body.offsetHeight;
			} else if (iframeid.Document && iframeid.Document.body.scrollHeight) {
				iframeid.height = iframeid.Document.body.scrollHeight;
			}
		}
	}
}
function openWindow(url,w,h){
    var iTop = (window.screen.availHeight-30-h)/2;       //获得窗口的垂直位置;
    var iLeft = (window.screen.availWidth-10-w)/2;           //获得窗口的水平位置;
    window.open(url,'_blank','height='+h+',width='+w+',top='+iTop+',left='+iLeft+',scrollbars=yes,toolbar=no,menubar=no,location=no,resizable=yes');
}

function buildTableData(pageIndex,url,bodyId,barId,condition) {			
	var sendData = "page.pageNo="+pageIndex+"&page.url="+url+"&page.bodyId="+bodyId+"&page.paginationBarId="+barId+"&page.condition="+encode64(condition);			
	if(condition!=null){			
		sendData+="&"+condition;			
	}	
	$.ajax({ // 这里使用到Jquery的ajax方法，具体使用在这里不详细叙述
		type: "POST",
		dataType: "html",
		url: url, // 请求的处理数据
		data: sendData,  // 传入的参数，第一个参数就是分页的页数，第二个参数为排序的依据
		// 下面的操作就是成功返回数据以后，进行数据的绑定
		success: function(data) {
			$("#"+bodyId).empty().append(data);
		}
	});
}

function sendRequest(url,type,condition,f){
	$.ajax({ // 这里使用到Jquery的ajax方法，具体使用在这里不详细叙述
		type: "POST",
		dataType: type,
		url: url, // 请求的处理数据
		data: condition,  // 传入的参数，第一个参数就是分页的页数，第二个参数为排序的依据
		// 下面的操作就是成功返回数据以后，进行数据的绑定
		success:function(data){
			if(f)
				f(data);
		}
	});
}

function sendHtmlReqest(url,condition,f){
	sendRequest(url,'html',condition,f);
}
function sendJsonRequest(url,condition,f){
	sendRequest(url,'json',condition,f);
}
function buildTableDataByPage(pageIndex,url,bodyId,barId,condition) {			
	var sendData = "page.pageNo="+pageIndex+"&page.url="+url+"&page.bodyId="+bodyId+"&page.paginationBarId="+barId+"&page.condition="+condition;			
	if(condition!=null){
		var con = decode64(condition);				
		sendData+="&"+con;			
	}				
	$.ajax({ // 这里使用到Jquery的ajax方法，具体使用在这里不详细叙述
		type: "POST",
		dataType: "html",
		url: url, // 请求的处理数据
		data: sendData,  // 传入的参数，第一个参数就是分页的页数，第二个参数为排序的依据
		// 下面的操作就是成功返回数据以后，进行数据的绑定
		success: function(data) {
			$("#"+bodyId).empty().append(data);
		}
	});
}

function checkAll(obj,name){
	$(":checkbox[name='"+name+"']").each(function(index){
		this.checked = obj.checked;
	});
}
function changeTab(url,f){
	document.forms[f].action = url;
	document.forms[f].submit();
}



function showPop(id,tle,w,h) {
	$(id).window( {
		title : tle,
		width : w,
		modal : true,
		shadow : false,
		closed : false,
		height : h
	});

	w = ($(window).width() - $(id).outerWidth())/2;
	h = ($(window).height() - $(id).outerHeight())/2-20;
	id=".window:has(div[id="+id.substring(1,id.length)+"])";
	
	$(id).css({
		  position:'absolute',
		  left: w,
		   top: h
		 });
				
}

function closePop(id){
	$(id).window('close');//默认不显示窗口	
}

function pollingService(url,interval){
	$(document).everyTime(interval,function(){jsonRequest(url);});
}
function defaultPolling(){
	pollingService("${pageContext.request.contextPath}/internal/internalPolling.action","6hs");
}
